using Domain.Permissions;
using System;
using UserInterface;
using UserInterface.UserControls;
using UserInterface.Misc;

namespace UserInterface.Admin
{
    public partial class BoardAdmin : System.Web.UI.MasterPage
    {
        private NavigationData navigationData = new NavigationData();

        protected void Page_Load(object sender, EventArgs e)
        {
            PermissionManager permissionManager = new PermissionManager(SessionManager.CurrentSession.User);
            if (!permissionManager.IsAdministrator())
            {
                Response.Redirect("~/Index.aspx");
            }
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            BindNavigationData();
            BoardMessages.BindData();
        }

        public Messages Messages
        {
            get { return BoardMessages; }
        }

        public void AddNavigationItem(string name, string path)
        {
            navigationData.AddPathItem(name, path);
        }

        private void BindNavigationData()
        {
            if (navigationData.MapPathItems.Count > 0)
            {
                SubNavigationPlaceHolder.Visible = true;
                SubNavigationRepeater.DataSource = navigationData.MapPathItems;
                SubNavigationRepeater.DataBind();
            }
            else
            {
                SubNavigationPlaceHolder.Visible = false;
            }
        }
    }
}
